<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <el-col :md="8" :sm="12">
                        <el-form-item label="星期几:" prop="week_day.value">
                            <el-select v-model="queryParams.week_day.value" placeholder="请选择星期几">
                                <el-option v-for="(el, idx) in weekOptions" :key="idx" :value="el.value" :label="el.label"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :md="8" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open">添加</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete">删除</el-button>
                </el-col>
                <el-col :span="1.5" v-if="false">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport"
                               v-hasPermi="api.export">导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>
            <!-- 列表 -->
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <template v-slot:action>
                    <el-table-column label="操作" width="180">
                        <template slot-scope="scope">
                            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)">编辑</el-button>
                            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </template>
            </qa-table>
            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>
        <!-- 编辑弹窗 -->
       <el-dialog :title="!disabled ? ( findFormData[pk] ? '编辑' : '添加' ) : '详情'" :visible="editOpen" :before-close="beforeClose" destroy-on-close append-to-body>
            <EditForm ref="editForm" :findFormData="findFormData" :disabled="disabled" @submitForm="submitForm"
                      :doctorId="queryObj.doctor_id" :weekOptions="weekOptions"
                      :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>
    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm },
    props: {
        queryObj: {
            type: Object,
            default: ()=> {}
        }
    },
    data() {
        return {
            // table结构
            columns: [
                {
                    visible: true,
                    label: '编号',
                    prop: 'id',
                    width: 60
                },
                {
                    visible: true,
                    label: '星期几',
                    prop: 'week_day',
                },
                {
                    visible: true,
                    label: '开始时间',
                    prop: 'start_time',
                },
                {
                    visible: true,
                    label: '结束时间',
                    prop: 'end_time',
                },
                {
                    visible: true,
                    label: '出诊地址',
                    prop: 'address',
                },
            ],
            // 接口地址
            api: {
                index: `/admin/ch.hospital_doctor_times/index`,
                find: `/admin/ch.hospital_doctor_times/find`,
                add: `/admin/ch.hospital_doctor_times/add`,
                edit: `/admin/ch.hospital_doctor_times/edit`,
                delete: `/admin/ch.hospital_doctor_times/delete`,
                export: `/admin/ch.hospital_doctor_times/export`,
                status: `/admin/ch.hospital_doctor_times/status`
            },
            editFormParams: {},
            // 搜索表单是否展开
            searchExpand: false,
            // 查询参数
            queryParams: {
                doctor_id: { value:undefined, op: '='},
                week_day: { value:undefined, op: '='},
            },
            weekOptions: [
                {value: 1, label: '星期一'},
                {value: 2, label: '星期二'},
                {value: 3, label: '星期三'},
                {value: 4, label: '星期四'},
                {value: 5, label: '星期五'},
                {value: 6, label: '星期六'},
                {value: 7, label: '星期天'},
            ],
            tableIsJoinLoad: false
        }
    },
    created() {
        if (this.queryObj.doctor_id) {
            this.queryParams.doctor_id.value = this.queryObj.doctor_id
        }
        this.initIndex()
    }
}
</script>
